/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.vsu.model;

import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import ru.vsu.domain.Bid;
import ru.vsu.domain.Thing;
import ru.vsu.service.ProfileService;

/**
 *  Бин, отвечающий за отображение страницы пользователя.
 *
 * @author Roman Velichkin <vrnroman@gmail.com>
 */
@Named
@SessionScoped
public class ProfileBean implements Serializable {

    @Inject
    private transient MainPage mainPage;

    @Inject
    private transient ThingBean thingBean;

    @EJB
    private ProfileService profileService;

    private Bid selectedBid;

    /** Creates a new instance of ProfileBean */
    public ProfileBean() {
    }


    public List<Thing> getUsersThings() {
        return profileService.getUsersThings(mainPage.getUserId());
    }


    public List<Bid> getUsersBid() {
        return profileService.getUsersBid(mainPage.getUserId());
    }

    public String goToThingInfo() {
        if (thingBean.getThing() == null) {
            return null;
        }
        return "thing.xhtml?faces-redirect=true";
    }

    public void createNewThing() {
        profileService.createSimpleThing(mainPage.getUserId());
    }

    public Bid getSelectedBid() {
        return selectedBid;
    }

    public void setSelectedBid(Bid selectedBid) {
        this.selectedBid = selectedBid;
    }

}
